package org.moonshot.cvm;

import java.util.ArrayList;

public class ChattyStack
{
    protected ArrayList<Object> mList = new ArrayList<Object> ();
    protected int n = -1;
    
    /**
     * Push an item on top of stack.
     * @param aObj
     */
    public void push(Object aObj)
    {
    	mList.add (aObj);
    	n++;
    }
    
    /**
     * Pop any number of items off the top of the stack.
     * @param i
     */
    public void pop(int i)
    {
    	while( i > 0 && n > 0 )
    	{
    		mList.remove (n);
    		i--; n--;
    	}
    }
    
    /**
     * Push the i'th item from the top, where top-of-stack is i=0
     * @param i
     */
    public void pull(int i)
    {
    	mList.add (mList.get (n - i));
    }
    
    /**
     * Peek at the item i items down from top, where top-of-stack is i=0
     * @param i
     * @return
     */
	public Object at (int i)
    {
	    return mList.get (n - i);
    }
}
